/*
 * Created by Jaren at 2021/10/29 11:29
 */

import 'package:binary/binary.dart';
import 'package:inmotion_protocol/base/vehicle_data.dart';
import 'package:inmotion_protocol/common/product_model.dart';
import 'package:inmotion_protocol/common/product_version.dart';
import 'package:inmotion_protocol/lorin/bean/base/base.dart';
import 'package:inmotion_protocol/lorin/bean/base/vehicle_real_time_info.dart';

abstract class AbsAllRealTimeInfo extends AllRealTimeData<AbsRealTimeInfo, AbsRealTimeState, AbsRealTimeError> {
  AbsAllRealTimeInfo(AbsRealTimeInfo realTimeInfo, AbsRealTimeState realTimeState, AbsRealTimeError realTimeError) : super(realTimeInfo, realTimeState, realTimeError);

  @override
  String toString() {
    return "AllRealTimeInfo{realTimeInfo=${realTimeInfo.toString()}, realTimeState=${realTimeState.toString()}, realTimeError=${realTimeError.toString()}";
  }
}

abstract class AbsSynthesizeRealTimeInfo extends VehicleSynthesizeRealTimeInfo<CommonVehicleRealTimeInfo, AbsRealTimeState, AbsRealTimeError> {
  AbsSynthesizeRealTimeInfo(CommonVehicleRealTimeInfo commonVehicleRealTimeInfo, AbsRealTimeState realTimeState, AbsRealTimeError realTimeError)
      : super(commonVehicleRealTimeInfo, realTimeState, realTimeError);

  @override
  String toString() {
    return "SynthesizeRealTimeInfo{vehicleRealTimeInfo=${commonVehicleRealTimeInfo.toString()}, realTimeState=${realTimeState.toString()}, realTimeError=${realTimeError.toString()}";
  }
}

abstract class AbsVehicleRealTimeInfo extends Base<AbsVehicleRealTimeInfo> with VehicleRealTimeInfo {

  AbsVehicleRealTimeInfo(ProductModel model, VersionWrapper version) : super(model, version);

  @override
  int length() {
    return compact!.length();
  }
}

abstract class AbsRealTimeInfo extends Base<AbsRealTimeInfo> with RealTimeInfo {
  Uint16 remainderRange = Uint16.zero;

  AbsRealTimeInfo(ProductModel model, VersionWrapper version) : super(model, version);

  @override
  int length() {
    return compact!.length();
  }
}

abstract class AbsRealTimeState extends Base<AbsRealTimeState> with RealTimeState {
  Uint4 dfuState = Uint4.zero;

  AbsRealTimeState(ProductModel model, VersionWrapper version) : super(model, version);

  @override
  int length() {
    return compact!.length();
  }
}

abstract class AbsRealTimeError extends Base<AbsRealTimeError> with RealTimeError {
  Int32 originalValue = Int32.zero;

  Uint4 motorHallState = Uint4.zero;
  Uint4 batteryState = Uint4.zero;
  Uint4 controllerComState = Uint4.zero;

  Uint4 voltageState = Uint4.zero;
  Uint4 overMosTempState = Uint4.zero;
  Uint4 overMotorTempState = Uint4.zero;
  Uint4 overBatteryTempState = Uint4.zero;

  AbsRealTimeError(ProductModel model, VersionWrapper version) : super(model, version);

  isStateOk(Uint4 state) {
    return state.value == 0;
  }

  @override
  int length() {
    return compact!.length();
  }
}

abstract class AbsBatteryRealTimeInfo extends Base<AbsBatteryRealTimeInfo> with BatteryRealTimeInfo {
  AbsBatteryRealTimeInfo(ProductModel model, VersionWrapper version) : super(model, version);
}
